package sw6.digipecs.database;

import android.database.Cursor;
import android.database.sqlite.SQLiteCursor;
import android.database.sqlite.SQLiteCursorDriver;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteQuery;

public class PictureActiveCursor extends SQLiteCursor {
	private static final String[] mColumns = { DBAdapter.DB_PictureSituation_Active, DBAdapter.DB_PictureSituation_Position };
	
	private static class Factory implements CursorFactory {
		@Override
		public Cursor newCursor(SQLiteDatabase db,
				SQLiteCursorDriver masterQuery, String editTable,
				SQLiteQuery query) {
			return new PictureActiveCursor(db, masterQuery, editTable, query);
		}
	}
	public static PictureActiveCursor queryActive(SQLiteDatabase mDb, int pic_id, int sid) {
		final String select = DBAdapter.DB_PictureSituation_Picture_ID + " = " + pic_id + " AND " + DBAdapter.DB_PictureSituation_Situation_ID + " = " + sid;
		return(PictureActiveCursor) mDb.queryWithFactory(new Factory(), true, DBAdapter.DB_PictureSituation, mColumns, select, null, null, null, DBAdapter.DB_PictureSituation_Position, null);
	}
	
	private int mActiveIndex;
	private int mPositionIndex;
	public PictureActiveCursor(SQLiteDatabase db, SQLiteCursorDriver driver,
			String editTable, SQLiteQuery query) {
		super(db, driver, editTable, query);
		
		mActiveIndex = getColumnIndexOrThrow(DBAdapter.DB_PictureSituation_Active);
		mPositionIndex = getColumnIndexOrThrow(DBAdapter.DB_PictureSituation_Position);
	}
	
	public boolean getPictureActiveState() {
		int activeState = getInt(mActiveIndex);
		return (activeState == 0) ? true : false;
	}
	
	public int getPicturePostion(){
		return getInt(mPositionIndex);
	}
}
